Bandit Write-up Level 2

Posted by CLoveYC on April 3, 2024

Goal:

Using command to get the password which is stored in a file called '-'.

Login command: ssh bandit1@bandit.labs.overthewire.org -p 2220

Password: NH2SXQwcBdpmTEzi3bvBHMM9H66vVXjL

My Solution:

As we know, 'cat' can help us view a file. But what if a file name starts with '-'? If you do nothing and simply add the file after the command, the system will consider the filename as a parameter. As a result, we have two solutions that can be used. First, using standard input by adding '<' after the command. It'll be like 'cat < [file]'. On the other hand, we can use the file's path. The most convenient way in this case is './-[file]'. You specify the location of the current directory and the file. By using one of these methods, we can obtain the key: rRGizSaX8Mk1RTb1CNQoXTcYZWU6lgzi.

Difference

With two different solutions in hand, a question arises: What are the differences between 'cat < -' for standard input and 'cat ./-' for a relative path? From the user's perspective, they appear to be the same. The difference is that when you use standard input, the system places the file into the 'cat' command, which is why you can see it. Meanwhile, the relative path functions just like a normal 'cat' command. By specifying the path, you can avoid the system considering it as a parameter. Comparing both solutions, the relative path is more reliable. Due to the path it takes, the system won't misjudge any file starting with '-' as a parameter, which can avoid some potential errors.

The Key

rRGizSaX8Mk1RTb1CNQoXTcYZWU6lgzi



References

man cat

https://www.unix.com/unix-for-dummies-questions-and-answers/11998-how-cat-file-name-starts.html

https://askubuntu.com/questions/1190700/what-is-the-difference-between-cat-filename-and-cat-filename

https://stackoverflow.com/questions/42187323/how-to-open-a-dashed-filename-using-terminal